﻿Imports System.Globalization
Imports System.Collections.Generic

Public Class frmConfiguracionentreNiveles
    Dim vtn_frmConfiguracionEntreNiveles As frmConfiguracionentreNiveles
    Private objAlumnoLN As AlumnoLN
    Private objNivelLN As NivelLN
    Private Sub frmConfiguracionentreNiveles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objAlumnoLN = New AlumnoLN
        Me.dgvNivel1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        Me.dgvNivel2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        Dim dsListaNiveles1 As DataSet
        Dim dsListaNiveles2 As DataSet
        objNivelLN = New NivelLN
        'Para no permitir modificaciones sobre el combo box
        'cmbNivel1.DropDownStyle = ComboBoxStyle.DropDownList
        'cmbNivel2.DropDownStyle = ComboBoxStyle.DropDownList

        dsListaNiveles1 = objNivelLN.fBuscarNiveles()
        dsListaNiveles2 = objNivelLN.fBuscarNiveles()

        If Not (dsListaNiveles1 Is Nothing) Then
            pCargarCombos(dsListaNiveles1.Tables(0), 1)
        End If
        If Not (dsListaNiveles2 Is Nothing) Then
            pCargarCombos(dsListaNiveles2.Tables(0), 2)
        End If
    End Sub
    Private Sub pCargarCombos(ByVal dtNiveles As DataTable, ByVal i As Integer)
        If dtNiveles.Rows.Count = 0 Then
            MsgBox("No hay ningun nivel registrado", MsgBoxStyle.Information, "Error")
            Close()
            Exit Sub
        Else
            If (i = 1) Then
                cmbNivel1.DataSource = dtNiveles
                cmbNivel1.DisplayMember = "vchNombre"
            Else
                cmbNivel2.DataSource = dtNiveles
                cmbNivel2.DisplayMember = "vchNombre"
                'cmbNivel1.ValueMember = "vchValor"
            End If
        End If
    End Sub
   

    Private Sub btnBuscarNiveles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscarNiveles.Click
        Me.pLimpiarGrillas()
        Dim lAlumnos1 As List(Of AlumnoEN)
        Dim lAlumnos2 As List(Of AlumnoEN)
        Dim eleccion As String
        eleccion = cmbNivel1.GetItemText(cmbNivel1.SelectedItem)
        lAlumnos1 = objAlumnoLN.fBuscarAlumnos(cmbNivel1.GetItemText(cmbNivel1.SelectedItem))
        lAlumnos2 = objAlumnoLN.fBuscarAlumnos(cmbNivel2.GetItemText(cmbNivel2.SelectedItem))
        Me.pCargarGrillas(lAlumnos1, lAlumnos2)

    End Sub

    Private Sub pCargarGrillas(ByVal lAlumnos1 As List(Of AlumnoEN), ByVal lAlumnos2 As List(Of AlumnoEN))
        Dim i As Integer
        For i = 0 To lAlumnos1.Count - 1
            Me.dgvNivel1.Rows.Add(lAlumnos1.Item(i).IdAlumno, lAlumnos1.Item(i).NombreAlumno + " " + lAlumnos1.Item(i).ApePaternoAlumno + " " + lAlumnos1.Item(i).ApeMaternoAlumno, lAlumnos1.Item(i).NombreGradoAlumno)
        Next
        Dim j As Integer
        For j = 0 To lAlumnos2.Count - 1
            Me.dgvNivel2.Rows.Add(lAlumnos2.Item(j).IdAlumno, lAlumnos2.Item(j).NombreAlumno + " " + lAlumnos2.Item(j).ApePaternoAlumno + " " + lAlumnos2.Item(j).ApeMaternoAlumno, lAlumnos2.Item(j).NombreGradoAlumno)
        Next
    End Sub
    Private Sub btnPasaIz_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPasaIz.Click
        If Me.dgvNivel2.SelectedRows.Count > 0 Then
            Dim i As Integer
            For i = 0 To Me.dgvNivel2.SelectedRows.Count - 1
                Me.dgvNivel1.Rows.Add(dgvNivel2.SelectedRows.Item(i).Cells(0).Value, dgvNivel2.SelectedRows.Item(i).Cells(1).Value, dgvNivel2.SelectedRows.Item(i).Cells(2).Value)
            Next i
            For i = 0 To Me.dgvNivel2.SelectedRows.Count - 1
                Me.dgvNivel2.Rows.RemoveAt(Me.dgvNivel2.SelectedRows.Item(0).Index)
            Next i
        End If
    End Sub

    Private Sub btnPasaDerecha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPasaDerecha.Click

        If Me.dgvNivel1.SelectedRows.Count > 0 Then
            Dim j As Integer
            For j = 0 To Me.dgvNivel1.SelectedRows.Count - 1
                Me.dgvNivel2.Rows.Add(dgvNivel1.SelectedRows.Item(j).Cells(0).Value, dgvNivel1.SelectedRows.Item(j).Cells(1).Value, dgvNivel1.SelectedRows.Item(j).Cells(2).Value)
            Next j
            For j = 0 To Me.dgvNivel1.SelectedRows.Count - 1
                Me.dgvNivel1.Rows.RemoveAt(Me.dgvNivel1.SelectedRows.Item(0).Index)
            Next j
        End If
    End Sub
    Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuardar.Click

    End Sub
    Private Sub cmbNivel1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbNivel1.SelectedValueChanged
        
        Dim NivelNO As String
        Dim dsListaNiveles2 As DataSet
        objNivelLN = New NivelLN
        NivelNO = cmbNivel1.GetItemText(cmbNivel1.SelectedItem)
        dsListaNiveles2 = objNivelLN.fBuscarNiveles1(NivelNO)
        pCargarCombos(dsListaNiveles2.Tables(0), 2)
    End Sub
    'Private Sub cmbNivel2_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbNivel2.SelectedValueChanged

    '    Dim NivelNO As String
    '    Dim dsListaNiveles1 As DataSet
    '    objNivelLN = New NivelLN
    '    NivelNO = cmbNivel2.GetItemText(cmbNivel2.SelectedItem)
    '    dsListaNiveles1 = objNivelLN.fBuscarNiveles1(NivelNO)
    '    pCargarCombos(dsListaNiveles1.Tables(0), 1)
    'End Sub
#Region "VALIDACIONES"
    'Valida que se desee realmente cancelar la transaccion
    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        If MessageBox.Show("¿Desea cancelar la transacción?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
            'Button 1 es el Si, Button 2 es el No, Button 3 es el Cancel
            Me.Close()
            Me.Dispose()

        End If
    End Sub
#End Region
#Region "LIMPIEZA"

    'Limpiar las grillas
    Private Sub pLimpiarGrillas()
        dgvNivel1.Rows.Clear()
        dgvNivel2.Rows.Clear()
    End Sub
#End Region

End Class